package com.nowcoder.community.actuator;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author szq
 * @create 2023-03-29 9:58
 * @description 定制 Metrics 信息 - 统计某功能的访问次数
 */
//@Aspect
//@Component
public class MetricsAspect {

    private final Counter counter;

    public MetricsAspect(MeterRegistry meterRegistry) {
        counter = meterRegistry.counter("myService.method.running.counter");
    }

    @Pointcut("execution(* com.nowcoder.community.controller.HomeController.getIndexPage(..))")
    public void pointcut() {

    }

    // 前置通知
    @Before("pointcut()")
    public void before() {
        counter.increment();
    }

}
